from .models import denglu
from django.shortcuts import render
from django.http import HttpResponse
import json

# Create your views here.


def reg(request):
    list = denglu.objects.all()
    user=json.loads(request.body)
    for var in list:
        if user['username']!=var.username:
            denglu1=denglu(username=user['username'],password=user['password'])
            denglu1.save()
            ret={'code':0,'msg':'注册成功'}
        elif user['username']==var.username:
            if user['password']==var.password:
                ret={'code':1,'msg':'登录成功'}
            elif user['password']!=var.password:
                ret={'code':2,'msg':'密码错误'}
    return HttpResponse( json.dumps(ret) )